// ----------------------------------
// RSDK Project: Sonic 1/Sonic 2
// Script Description: Rotating Stair Object
// Script Author: Christan Whitehead/Simon Thomley
// Unpacked by Rubberduckycooly's script unpacker
// ----------------------------------

//-------Aliases-------//
private alias 52 : TYPE_ROTATINGSTAIR

// Function declarations
reserve function RotatingStair_DebugDraw
reserve function RotatingStair_DebugSpawn
reserve function RotatingStair_Function116

// Static Values

// Tables

function RotatingStair_DebugDraw
	temp0 = object.xpos
	temp0 -= 0x700000
	temp1 = object.ypos
	temp1 -= 0x700000
	temp2 = 0
	while temp2 < 8
		DrawSpriteXY(0, temp0, temp1)
		temp0 += 0x200000
		temp1 += 0x200000
		temp2++
	loop
end function


function RotatingStair_DebugSpawn
	CreateTempObject(TypeName[Rotating Stair], 0, object.xpos, object.ypos)
	object[tempObjectPos].value16 = object.xpos
	object[tempObjectPos].value17 = object.ypos
end function


function RotatingStair_Function116
	temp1 = temp5
	GetTableValue(temp0, temp3, StageSetup_table9)
	temp0 <<= 8
	if temp3 == 20
		temp0 >>= 1
	end if
	switch temp4
	case 0
		temp0 -= temp1
		temp0 += object.value16
		temp6 = temp0
		FlipSign(temp1)
		temp1 += object.value17
		temp7 = temp1
		break
	case 1
		temp0 -= temp1
		FlipSign(temp0)
		temp0 += object.value17
		temp7 = temp0
		temp1 += object.value16
		temp6 = temp1
		break
	case 2
		temp0 -= temp1
		FlipSign(temp0)
		temp0 += object.value16
		temp6 = temp0
		temp1 += object.value17
		temp7 = temp1
		break
	case 3
		temp0 -= temp1
		temp0 += object.value17
		temp7 = temp0
		FlipSign(temp1)
		temp1 += object.value16
		temp6 = temp1
		break
	end switch
	temp6 &= -0x10000
	temp7 &= -0x10000
	temp0 = temp6
	temp0 -= object.xpos
	temp1 = temp7
	temp1 -= object.ypos
	foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
		BoxCollisionTest(C_BOX, object.entityPos, -16, -16, 16, 16, currentPlayer, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO)
		if checkResult == 1
			object[currentPlayer].xpos += temp0
			object[currentPlayer].ypos += temp1
		end if
		if object[currentPlayer].gravity == GRAVITY_GROUND
			if checkResult == 4
				CallFunction(PlayerObject_Kill)
			end if
		end if
	next
end function


event ObjectMain
	temp4 = SLZSetup_value29
	temp5 = 0x100000
	temp3 = 20
	object.xpos = object.value0
	object.ypos = object.value1
	CallFunction(RotatingStair_Function116)
	object.value0 = temp6
	object.value1 = temp7
	temp4 ^= 2
	object.xpos = object.value2
	object.ypos = object.value3
	CallFunction(RotatingStair_Function116)
	object.value2 = temp6
	object.value3 = temp7
	temp4 ^= 2
	temp5 = 0x300000
	temp3 = 22
	object.xpos = object.value4
	object.ypos = object.value5
	CallFunction(RotatingStair_Function116)
	object.value4 = temp6
	object.value5 = temp7
	temp4 ^= 2
	object.xpos = object.value6
	object.ypos = object.value7
	CallFunction(RotatingStair_Function116)
	object.value6 = temp6
	object.value7 = temp7
	temp4 ^= 2
	temp5 = 0x500000
	temp3 = 24
	object.xpos = object.value8
	object.ypos = object.value9
	CallFunction(RotatingStair_Function116)
	object.value8 = temp6
	object.value9 = temp7
	temp4 ^= 2
	object.xpos = object.value10
	object.ypos = object.value11
	CallFunction(RotatingStair_Function116)
	object.value10 = temp6
	object.value11 = temp7
	temp4 ^= 2
	temp5 = 0x700000
	temp3 = 26
	object.xpos = object.value12
	object.ypos = object.value13
	CallFunction(RotatingStair_Function116)
	object.value12 = temp6
	object.value13 = temp7
	temp4 ^= 2
	object.xpos = object.value14
	object.ypos = object.value15
	CallFunction(RotatingStair_Function116)
	object.value14 = temp6
	object.value15 = temp7
	object.xpos = object.value16
	object.ypos = object.value17
end event


event ObjectDraw
	DrawSpriteXY(0, object.value0, object.value1)
	DrawSpriteXY(0, object.value2, object.value3)
	DrawSpriteXY(0, object.value4, object.value5)
	DrawSpriteXY(0, object.value6, object.value7)
	DrawSpriteXY(0, object.value8, object.value9)
	DrawSpriteXY(0, object.value10, object.value11)
	DrawSpriteXY(0, object.value12, object.value13)
	DrawSpriteXY(0, object.value14, object.value15)
end event


event ObjectStartup
	LoadSpriteSheet("SLZ/Objects.gif")
	SpriteFrame(-16, -16, 32, 32, 67, 26)
	foreach (TypeName[Rotating Stair], arrayPos0, ALL_ENTITIES)
		object[arrayPos0].value16 = object[arrayPos0].xpos
		object[arrayPos0].value17 = object[arrayPos0].ypos
	next
	SetTableValue(TypeName[Rotating Stair], DebugMode_ObjCount, DebugMode_TypesTable)
	SetTableValue(RotatingStair_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
	SetTableValue(RotatingStair_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
	DebugMode_ObjCount++
end event

event RSDKDraw
	DrawSprite(0)
end event

event RSDKLoad
	LoadSpriteSheet("Global/Display.gif")
	SpriteFrame(-16, -16, 32, 32, 1, 143)
end event
